package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeMethod;
import com.ruoyi.grape.service.IGrapeMethodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 防范补救措施Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/method")
public class GrapeMethodController extends BaseController
{
    @Autowired
    private IGrapeMethodService grapeMethodService;

    /**
     * 查询防范补救措施列表
     */
    @PreAuthorize("@ss.hasPermi('grape:method:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeMethod grapeMethod)
    {
        startPage();
        List<GrapeMethod> list = grapeMethodService.selectGrapeMethodList(grapeMethod);
        return getDataTable(list);
    }

    /**
     * 导出防范补救措施列表
     */
    @PreAuthorize("@ss.hasPermi('grape:method:export')")
    @Log(title = "防范补救措施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeMethod grapeMethod)
    {
        List<GrapeMethod> list = grapeMethodService.selectGrapeMethodList(grapeMethod);
        ExcelUtil<GrapeMethod> util = new ExcelUtil<GrapeMethod>(GrapeMethod.class);
        util.exportExcel(response, list, "防范补救措施数据");
    }

    /**
     * 获取防范补救措施详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:method:query')")
    @GetMapping(value = "/{methodId}")
    public AjaxResult getInfo(@PathVariable("methodId") Long methodId)
    {
        return success(grapeMethodService.selectGrapeMethodByMethodId(methodId));
    }

    /**
     * 新增防范补救措施
     */
    @PreAuthorize("@ss.hasPermi('grape:method:add')")
    @Log(title = "防范补救措施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeMethod grapeMethod)
    {
        return toAjax(grapeMethodService.insertGrapeMethod(grapeMethod));
    }

    /**
     * 修改防范补救措施
     */
    @PreAuthorize("@ss.hasPermi('grape:method:edit')")
    @Log(title = "防范补救措施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeMethod grapeMethod)
    {
        return toAjax(grapeMethodService.updateGrapeMethod(grapeMethod));
    }

    /**
     * 删除防范补救措施
     */
    @PreAuthorize("@ss.hasPermi('grape:method:remove')")
    @Log(title = "防范补救措施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{methodIds}")
    public AjaxResult remove(@PathVariable Long[] methodIds)
    {
        return toAjax(grapeMethodService.deleteGrapeMethodByMethodIds(methodIds));
    }
}
